

package edu.tfg.bean;

import edu.tfg.dao.PlanoDAO;
import edu.tfg.model.Plano;
import java.util.List;
import java.util.Objects;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Juarez
 */
@ManagedBean
@SessionScoped
public class PlanoBean {
    
    public PlanoBean() {
    }
    
    private Plano plano = new Plano();
    private PlanoDAO planoDAO = new PlanoDAO();
    private List listaPlano;

    public List getListaPlano() {
        return listaPlano;
    }

    public void setListaPlano(List listaPlano) {
        this.listaPlano = listaPlano;
    }

    public Plano getPlano() {
        return plano;
    }

    public void setPlano(Plano plano) {
        this.plano = plano;
    }

    public PlanoDAO getPlanoDAO() {
        return planoDAO;
    }

    public void setPlanoDAO(PlanoDAO planoDAO) {
        this.planoDAO = planoDAO;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 89 * hash + Objects.hashCode(this.plano);
        hash = 89 * hash + Objects.hashCode(this.planoDAO);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PlanoBean other = (PlanoBean) obj;
        if (!Objects.equals(this.plano, other.plano)) {
            return false;
        }
        if (!Objects.equals(this.planoDAO, other.planoDAO)) {
            return false;
        }
        return true;
    }
    
     public String adicionaPlano(){
        planoDAO.salvar(plano);
        return "index";
    }

     public String removePlano(){
        planoDAO.removePlano(plano);
        return "sucesso";
     }
     
     public List listarPlano(){
         listaPlano = planoDAO.listarPlano();
         return listaPlano;
     }
     public String alterarPlano(){
            planoDAO.alterarPlano(plano);
         return "index";
     }
     
     public String pesquisarPlano(){
         planoDAO.pesquisarPlano(null);
         return "index";
     }
    
    
}
